package com.fz.action;

import lombok.Data;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by webrx on 2017-09-14.
 */
@ParentPackage("struts-default")
@Namespace("/book")
@Data
public class BookAction {
    private String fn;

    @Action("/abc")
    public String abc() throws IOException {
        HttpServletResponse res = ServletActionContext.getResponse();
        res.setCharacterEncoding("utf-8");
        res.setContentType("text/html;charset=utf-8");
        PrintWriter out = res.getWriter();
        out.print("<h1>Struts2.5.13 入门案例</h1>");
        out.flush();
        out.close();
        //return "success";
        return null;
    }

    @Action(value="/ssss",results={@Result(type="plainText",params = {"charset","utf-8","location","/${fn}.jsp"})})
    public String ssss(){
        return "success";
    }
}
